<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>日期对象</title>
  </head>
  <body>
    <script>
      // 1、处理接口返回的数据
      var date = '2023-01-31T17:33:45+08:00';

      function formatDate(time) {
        var dt = new Date(time);
        var year = dt.getFullYear();
        var month = dt.getMonth() + 1;
        month = month < 10 ? '0' + month : month;
        var day = dt.getDate();
        day = day < 10 ? '0' + day : day;
        var hour = dt.getHours();
        hour = hour < 10 ? '0' + hour : hour;
        var min = dt.getMinutes();
        min = min < 10 ? '0' + min : min;
        var sec = dt.getSeconds();
        sec = sec < 10 ? '0' + sec : sec;
        return `${year}-${month}-${day} ${hour}:${min}:${sec}`;
      }

      console.log('处理后--', formatDate(date));
    </script>
  </body>
</html>
